package com.lzy.mall.product.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.lzy.mall.product.entity.PmsSpuImages;
import com.lzy.mall.product.dao.PmsSpuImagesDao;
import com.lzy.mall.product.service.PmsSpuImagesService;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;


/**
 * spu图片(PmsSpuImages)表服务实现类
 *
 * @author lzy
 * @since 2021-08-25 11:41:23
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class PmsSpuImagesServiceImpl implements PmsSpuImagesService {
    private final PmsSpuImagesDao pmsSpuImagesDao;

    @Override
    public void saveImages(Long id, List<String> images) {
        if (ObjectUtil.isNull(id) || CollUtil.isEmpty(images)){
            //TODO 异常
        }
        List<PmsSpuImages> list = images.stream()
                .map(str -> {
                    PmsSpuImages build = PmsSpuImages.builder()
                            .spuId(id)
                            .imgUrl(str)
                            .build();
                    return build;
                }).collect(Collectors.toList());
        pmsSpuImagesDao.insertBatch(list);
    }
}
